package com.kangaroo.myhome.service.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.kangaroo.myhome.mapper.TSysUserMapper;
import com.kangaroo.myhome.model.TSysUser;
import com.kangaroo.myhome.model.TSysUserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import com.kangaroo.myhome.service.UserService;

@Service
public class SysUserServiceImpl implements UserService {

	@Autowired
	private TSysUserMapper tSysUserMapper;

	@Override
	public TSysUser findByUsername(String username) {

		TSysUserExample example = new TSysUserExample();

		example.createCriteria().andAccountEqualTo(username);
		List<TSysUser> users = tSysUserMapper.selectByExample(example);
		TSysUser user = null;

		if(users!=null && users.size()>0){
			user = users.get(0);
			// user.setPassword(new BCryptPasswordEncoder().encode(user.getPassword()));
		}
		return user;
	}

	@Override
	public Set<String> findPermissions(String username) {
		Set<String> permissions = new HashSet<>();
		// permissions.add("sys:user:view");
		permissions.add("sys:user:add");
		permissions.add("sys:user:edit");
		// permissions.add("sys:user:delete");
		return permissions;
	}

}
